<?php

if (! file_exists(realpath(dirname(__FILE__)) . '/../vendor/autoload.php'))
    exit("autoload文件不存在");

require realpath(dirname(__FILE__)) . '/../vendor/autoload.php';

use partner\functions\wechat\lib\BankAccountInfo\AccountCertInfo;
use partner\functions\wechat\lib\BankAccountInfo;
use partner\functions\wechat\lib\ContactInfo;
use partner\Partner;
use WeChatPay\Crypto\Rsa;


$path_to_platform_cert = realpath(dirname(__FILE__)) . '/cert/wechat/platform_cert.pem';
// $rsa = Rsa::from($path_to_platform_cert, Rsa::KEY_TYPE_PRIVATE);
// 测试用
$rsa = true;

// 银行账户证明材料
$account_cert_info_params = [
    'settlement_cert_pic' => realpath(dirname(__FILE__)) . '/cert/wechat/platform_cert.pem',
    'relation_cert_pic' => realpath(dirname(__FILE__)) . '/cert/wechat/platform_cert.pem',
    'other_cert_pics' => [
        realpath(dirname(__FILE__)) . '/cert/wechat/platform_cert.pem'
    ],
    'test' => '字符串'
];
$account_cert_info = new AccountCertInfo($account_cert_info_params, true);
// var_dump($account_cert_info);

// 随机一个城市出来
$cities_in_json = file_get_contents(realpath(dirname(__FILE__)) . '/../partner/functions/wechat/doc/cities.json');
$cities = json_decode($cities_in_json, true);
$city = $cities[rand(0, count($cities))];

// 结算银行账户
$bank_account_info_params = [
    'bank_account_type' => 'BANK_ACCOUNT_TYPE_CORPORATE',
    'account_name' => '开户名称',
    'account_bank' => '厦门国际银行',
    'bank_address_code' => $city["code"],
    'bank_branch_id' => '',
    'bank_name' => '厦门国际银行股份有限公司北京朝阳支行',
    'account_number' => '11111',
    'account_cert_info' => $account_cert_info
];
$bank_account_info = new BankAccountInfo($bank_account_info_params, $rsa);

$pay = new Partner([
    "mode" => "testing",
    // "platform_cert" => realpath(dirname(__FILE__)) . '/cert/wechat/platform_cert.pem',
    // "merchant_private_key_instance" => $rsa
    // 测试用
    "merchant_private_key_instance" => true,
    // 调用接口所需的类
    "bank_account_info" => $bank_account_info
]);
$response = $pay->wechat_partner->apply();
var_dump($response);

$contact_info = new ContactInfo([], $rsa);
var_dump($contact_info->getAllowedContactType());
var_dump($contact_info->getAllowedContactIdType());
// var_dump($pay->wechat_partner->getContactTypeArray());
// var_dump($pay->wechat_partner->getContactIdTypeArray());



// $response = $pay->alipay_partner->apply();
// var_dump($response);
